package com.gg.controller;

import java.util.Set;

import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Component
public class Zedis {
	private JedisPool pool;
	
	public Zedis(JedisPool pool) {
		this.pool = pool;
	}
	
	public Zedis() {
		this.pool = new JedisPool(new JedisPoolConfig(), "localhost");
	}
	public void set(String key, String value) {
		Jedis jedis = pool.getResource();
		
		try {
			jedis.set(key, value);
		} finally {
			pool.returnResource(jedis);
		}
		
	}

	public Set<String> zrange(String key, int min, int max) {
		Jedis jedis = pool.getResource();
		try {
			return jedis.zrange(key, min, max);			
		} finally {
			pool.returnResource(jedis);
		}
	}

	public void zrem(String string, String key) {
		Jedis jedis = pool.getResource();
		try {
			jedis.zrem("build:woodcutter", key);
		} finally {
			pool.returnResource(jedis);
		}
	}
}
